<?php
namespace Admin\Controller;
use User\Api\UserApi;

class CommonController extends \Think\Controller {

    public function verify(){
        $verify = new \Think\Verify();
        $verify->entry(1);
    }
    
    public function getAreaOptions(){
        $commonLogic = new \Common\Logic\CommonLogic();
        //1级部门
        $parentid = I('request.id', 0);
		$mutil_level_data_options = $commonLogic->getAreaOptions(array('parentid'=>$parentid));
        $result = array();
        $result['count'] = count($mutil_level_data_options);
        $result['data_list'] = array();
        foreach($mutil_level_data_options as $key => $value)
        {
            $temp = array();
            $temp['key'] = $key;
            $temp['value'] = $value;
            $result['data_list'][] = $temp;
        }
        echo json_encode($result);
    }
    
    public function upload(){
        //上传文件分类
        $type = I('request.type');
        if(empty($type) || !in_array($type, array('hall', 'recharge', 'auth_pic'))) exit('type?');

        $upload = new \Think\Upload();;// 实例化上传类
        //$upload->maxSize  = 3145728 ;// 设置附件上传大小
		$upload->exts  = array('jpg', 'gif', 'png', 'jpeg', 'gif', 'bmp');// 设置附件上传类型
        $upload->rootPath = ROOT_PATH.C('UPLOAD_DIR');
        $upload->savePath =  $type.'/';// 设置附件上传目录
        $upload->subName =  '';// 按日期目录
        $info = $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $data['status'] = 0;
            $data['info']   = $upload->getError();
        }else{// 上传成功 获取上传文件信息
            $data['status'] = 1;
            $data['url']   = C('UPLOAD_DIR').$upload->savePath.$info['Filedata']['savename'];
        }
        $this->ajaxReturn($data);
    }
	
	//选择主代理，返回朱代理下的一级代理
	public function chooseAgentLevel1()
	{
		$result = array();
		
		//默认为空
        $result = '<option value="0"></option>';
		
		$agent_id = I('request.agent_id', '', 'intval');
		
		$model = M();
		$sql = 'SELECT id,agent_name FROM mt_agent_info WHERE pid = "'.$agent_id.'"';
		$rs = $model->query($sql);
		foreach($rs as $key => $value) {
			$result .= '<option value="'.$value['id'].'">'.$value['agent_name'].'</option>';
		}
		
		$this->ajaxReturn($result);
    }
	
	//选择主代理，返回朱代理下的二级代理
	public function chooseAgentLevel()
	{
		$result = array();
		
		//默认为空
        $result = '<option value="0"></option>';
		
		$pid = I('request.pid', '', 'intval');
		
		$model = M();
		$sql = 'SELECT id,agent_name FROM mt_agent_info WHERE pid = "'.$pid.'"';
		$rs = $model->query($sql);
		foreach($rs as $key => $value) {
			$result .= '<option value="'.$value['id'].'">'.$value['agent_name'].'</option>';
		}
		
		//查询代理2016计费方式
		$agent_level = I('request.agent_level', 0);
		if(1 == $agent_level) {
			$agentModel = M('Agent');
			$agent = $agentModel->where('id="'.$pid.'"')->find();
			!$agent['billing_video_play_type'] && $agent['billing_video_play_type'] = 0;
			$result .= '#'.$agent['billing_video_play_type'];
		}
		
		
		$this->ajaxReturn($result);
    }
}
